//
//  CHLGRankingViewController.m
//  BallRankingProject
//
//  Created by lanou3g on 15/6/2.
//  Copyright (c) 2015年 luojian. All rights reserved.
//

#import "CHLGRankingViewController.h"

@interface CHLGRankingViewController ()

@end

@implementation CHLGRankingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   // self.navigationController.navigationBar.translucent = NO;
    CGRect fram=self.view.frame;
    fram.origin.x=CGRectGetWidth(self.view.frame)*2;
    fram.size.height=CGRectGetHeight(self.view.frame)-44;
    self.view.frame=fram;
    [self getMessage];
    [self addCegmentView];
    [self addIntegralView];
    

    
}
//添加标签视图
-(void)addCegmentView
{ NSArray *arr=[NSArray arrayWithObjects:@"积分榜",@"射手榜",@"助攻榜", nil];
    self.chlgCegment=[[UISegmentedControl alloc] initWithItems:arr];
    _chlgCegment.frame=CGRectMake(0,0, CGRectGetWidth(self.view.frame),40);
    _chlgCegment.selectedSegmentIndex=0;
    [self.view addSubview:_chlgCegment];
     [_chlgCegment addTarget:self action:@selector(changeView:) forControlEvents:(UIControlEventValueChanged)];
   // _chlgCegment.backgroundColor=[UIColor colorWithRed:0.009 green:1.000 blue:0.008 alpha:1.000];
   // _chlgCegment.backgroundColor=[UIColor whiteColor];
    
    //去掉颜色
    self.chlgCegment.tintColor =[UIColor clearColor];
    //设置选中字体的颜色
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:14],NSForegroundColorAttributeName: [UIColor whiteColor]};
    [self.chlgCegment setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];
    //设置未选中的字体颜色
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:12],NSForegroundColorAttributeName: [UIColor colorWithRed:72/255.0 green:105/255.0 blue:141/255.0 alpha:1.0]};
    [self.chlgCegment setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    self.chlgCegment.backgroundColor=[UIColor colorWithRed:26/255.0 green:52/255.0 blue:78/255.0 alpha:1.000];

}
//请求数据
- (void)getMessage
{
    self.integralDic =[NSDictionary dictionary];
    self.shooterDic=[NSDictionary dictionary];
    self.assistDic=[NSDictionary dictionary];
    NSURL *url=[NSURL URLWithString:CHLGMIC];
    NSData *data=[NSData dataWithContentsOfURL:url];
    if (data==nil) {
        
        return ;
    }
    NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
   // NSLog(@"%@",dic);
    
    NSArray *array=[dic objectForKeyedSubscript:@"result"];
    _integralDic=array[0];
    _shooterDic=array[1];
    _assistDic=array[2];
    
}
//积分榜视图
- (void)addIntegralView
{
   self.webView =[[UIWebView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(_chlgCegment.frame), CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-CGRectGetHeight(_chlgCegment.frame)-64)];
    NSString *string=[_integralDic objectForKey:@"web_url"];
    NSURL *url=[NSURL URLWithString:string];
    NSURLRequest *request=[NSURLRequest requestWithURL:url];
    _webView.scrollView.backgroundColor=[UIColor whiteColor];
    [_webView loadRequest:request];
    [self.view addSubview:_webView];
   
}
//实现segment方法
- (void)changeView:(UISegmentedControl *)Seg
{
    switch (_chlgCegment.selectedSegmentIndex) {
        case 0:
        
                [_shooterVC.view removeFromSuperview];
                [_assistVC.view removeFromSuperview];
                [self.view addSubview:_webView];
            break;
        case 1:
        {
                [_assistVC.view removeFromSuperview];
                [_webView removeFromSuperview];
                [self addShooterView];
                //_shooterVC.view.backgroundColor=[UIColor colorWithRed:0.936 green:0.844 blue:0.977 alpha:1.000];
        }
            
            break;
        case 2:
        {
            
                [_shooterVC.view removeFromSuperview];
                [_webView removeFromSuperview];
                [self insertAssistView];
                //_assistVC.view.backgroundColor=[UIColor colorWithRed:
        }
            break;
        default:
            break;
    }
    
}
//射手榜视图
- (void)addShooterView
{
    self.shooterVC=[[ShooterViewController alloc] init];
    [self addChildViewController:_shooterVC];
    //CGRect frame=_webView.frame;

   // shooterVC.view.frame=_webView.frame;
    _shooterVC.dic=_shooterDic;
    _shooterVC.view.frame=CGRectMake(0, CGRectGetHeight(_chlgCegment.frame), CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-CGRectGetHeight(_chlgCegment.frame)-64);
    [self.view addSubview:_shooterVC.view];
}
//助攻榜视图
- (void)insertAssistView
{

    self.assistVC=[[ShooterViewController alloc] init];
    [self addChildViewController:_assistVC];
    //CGRect frame=_webView.frame;
    
    // shooterVC.view.frame=_webView.frame;
    _assistVC.dic=_assistDic;
    _assistVC.view.frame=CGRectMake(0, CGRectGetHeight(_chlgCegment.frame), CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)-CGRectGetHeight(_chlgCegment.frame)-64);
   [self.view addSubview:_assistVC.view];
    
    
    


}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
